package com.example.mardan.views;

        import androidx.appcompat.app.AppCompatActivity;
        import androidx.lifecycle.Observer;
        import androidx.lifecycle.ViewModelProvider;
        import androidx.recyclerview.widget.LinearLayoutManager;
        import androidx.recyclerview.widget.RecyclerView;

        import android.os.Bundle;

        import com.example.mardan.adapter.TangShiAdapter;
        import com.example.mardan.entity.TangshiChapter;
        import com.example.mardan.viewmodel.TangShiViewModel;
        import com.example.read.R;

        import java.util.List;

public class TangShiActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private TangShiViewModel viewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tangshi);

        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        viewModel = new ViewModelProvider(this).get(TangShiViewModel.class);
        viewModel.getTangShiList().observe(this, new Observer<List<TangshiChapter.ResultDTO>>() {
            @Override
            public void onChanged(List<TangshiChapter.ResultDTO> tangShiList) {
                TangShiAdapter adapter = new TangShiAdapter(tangShiList);
                recyclerView.setAdapter(adapter);
            }
        });
    }
}
